package com.freedom.clue.verifyHandler;

import cn.afterturn.easypoi.excel.entity.result.ExcelVerifyHandlerResult;
import cn.afterturn.easypoi.handler.inter.IExcelVerifyHandler;
import com.freedom.auth.vo.EmployeeImportVo;
import com.freedom.org.domain.Employee;
import com.freedom.org.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class EmployeeVerifyHandler implements IExcelVerifyHandler<EmployeeImportVo> {
    @Autowired
    private IEmployeeService service;

    @Override
    public ExcelVerifyHandlerResult verifyHandler ( EmployeeImportVo employeeImportVo ) {
        ExcelVerifyHandlerResult result = new ExcelVerifyHandlerResult();
        String username = employeeImportVo.getUsername();

        // 比对数据库是否有这个线索客户
        Employee employee = service.getByUserName(username);

        if (employee != null) {
            // 校验失败
            result.setMsg("唯一校验失败");
            result.setSuccess(false);
            return result;
        }
        result.setSuccess(true);
        return result;
    }
}

